/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.instructional.example.swing.tester;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;

import com.fricano.java42.instructional.example.swing.J42JLabel_01;
import com.fricano.java42.sequencer.J42Helper;
import com.fricano.java42.sequencer.J42Sequencer;

public class JLabel_Moving_Tester_02 extends JLabel {

    final private static long         serialVersionUID     = -42L;

    final private static J42JLabel_01 instructionalExample = new J42JLabel_01(" TEST TESTING TEST ");

    public static void main(final String[] args) throws Exception {

        instructionalExample.setFont(new Font("System", Font.PLAIN, 24));
        instructionalExample.setForeground(Color.WHITE);
        instructionalExample.setBackground(new Color(111, 1, 142, 129));

        new J42Sequencer<JFrame>() {

            private boolean state = false;

            @Override
            public void doSequence0_CreateComponents(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {
            }

            @Override
            public void doSequence1_AddComponents(final JFrame jFrame, final Container contentPane, final J42Helper<JFrame> helper) {
                final JButton jButton = new JButton("Click Me");
                jButton.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        if (state) {
                            contentPane.add(instructionalExample);
                            contentPane.validate();
                            instructionalExample.moveIt(jFrame);
                            state = false;
                        }
                        else {
                            contentPane.remove(instructionalExample);
                            contentPane.repaint();
                            final JWindow jWindow = instructionalExample.moveIt(jFrame);
                            jWindow.setBackground(new Color(0, 0, 0, 0));
                            state = true;
                        }
                    }
                });

                contentPane.add(jButton);
                contentPane.add(instructionalExample);
            }

            @Override
            public void doSequence2_LocateSizePackShow(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {
                window.setLocationRelativeTo(null);
                window.setVisible(true);
            }

            @Override
            public void doSequence3_StartApplication(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {
            }

            @Override
            public void doSequence9_StopApplication(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {
                System.exit(0);
            }

        };
    }

}
